#!/usr/bin/env python

import gtk
import gettext
import constants
from mxit import handles
from blend import const
from signals import addContactDialogSignals

gettext.install('blendIT','locale');


class addContactDialog(gtk.Dialog):
   
   def __init__(self,blend,window,group=None):
      gtk.Dialog.__init__(self,_("Add New Contact"), window,
                          gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                          (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                          gtk.STOCK_ADD, gtk.RESPONSE_ACCEPT));

      sigs = addContactDialogSignals.signals(blend);
      self.set_icon_from_file(constants.IMG_Buddy);
      self.connect('response',sigs.on_response,self);
      
      self.drawDialog(blend.conn.roster.all_group_names,group);

      def sig(widget): widget.destroy();
      self.connect('close',sig);
      self.set_border_width(4);    


   def drawDialog(self,groups,group):  
      table = gtk.Table(rows=4,columns=2);

      # Alias
      aliasLabel = gtk.Label(_("Alias:"));
      aliasLabel.show();
      table.attach(aliasLabel,0,1,0,1,gtk.FILL);
      
      self.aliasTextEntry = gtk.Entry();
      self.aliasTextEntry.show();
      table.attach(self.aliasTextEntry,1,2,0,1,gtk.EXPAND|gtk.FILL);

      
      # Number / JID
      jidLabel = gtk.Label(_("Contact Number:"));
      jidLabel.show();
      table.attach(jidLabel,0,1,1,2,gtk.FILL);
      
      self.jidTextEntry = gtk.Entry();
      self.jidTextEntry.show();
      table.attach(self.jidTextEntry,1,2,1,2,gtk.EXPAND|gtk.FILL);
      
      # Invitation Message
      inviteLabel = gtk.Label(_("Invite Message:"));
      inviteLabel.show();
      table.attach(inviteLabel,0,1,2,3,gtk.FILL);
      
      self.inviteTextEntry = gtk.Entry();
      self.inviteTextEntry.show();
      table.attach(self.inviteTextEntry,1,2,2,3,gtk.EXPAND|gtk.FILL);
     
      # Group 
      groupComboLabel = gtk.Label(_("Group:"));
      groupComboLabel.show();
      table.attach(groupComboLabel,0,1,3,4,gtk.FILL);
      
      # Combo box for group selection
      self.groupComboBox = gtk.combo_box_new_text();
      index = 0;
      nogrp = 0;
      i=0;

      groups.remove("MXit Services");

      for grp in groups:
         if str(grp) == "":           
            self.groupComboBox.append_text("No Group");
            nogrp = i;
         else:
            self.groupComboBox.append_text(grp);
         if group == grp:
            index = i;
         i=i+1;

      if group != None:
         self.groupComboBox.set_active(index);
      else:
         self.groupComboBox.set_active(nogrp);
         
      self.groupComboBox.show();
      table.attach(self.groupComboBox,1,2,3,4,gtk.FILL);
      
      table.show();
      table.set_row_spacings(4);
      table.set_col_spacings(4);
      self.vbox.pack_start(table,True,True,0);
